<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<title>Heading Bidi Tests</title>
<script type="text/javascript" src="../../../deviceTheme.js"></script>
<script type="text/javascript" src="../../../../../dojo/dojo.js" data-dojo-config="async: true, parseOnLoad: true,  has: {'dojo-bidi': true }"></script>
<script language="JavaScript" type="text/javascript">

	require([
		"dojo/sniff",
		"dojo/dom-construct", // dojo.place
		"dojo/_base/window",
		"dojo/ready", // dojo.ready
		"dijit/registry",  // dijit.byId
		"doh/runner",	//doh functions
		"dojox/mobile/bidi/common",
		"dojox/mobile/Heading",	
		"dojox/mobile",				// This is a mobile app.
		"dojox/mobile/View",		// This mobile app uses mobile view
		"dojox/mobile/compat",		// This mobile app supports running on desktop browsers
		"dojox/mobile/parser"		// This mobile app uses declarative programming with fast mobile parser
		
	], function(has, domConst, win, ready, registry, runner, common, Heading){

		function _createHeadingProgrammatically(){
			var demoWidget = new Heading({label:"Pragramm Heading!", textDir:"auto", id:"hdn", back:"\u05e9\u05d9\u05de\u05d5\u05e9\u0020\u05d1\u05ea\u05d2\u05d9\u05d5\u05ea BACK..."});
			win.body().appendChild(demoWidget.domNode);
			win.body().appendChild(domConst.create("br"));
			return demoWidget;			
		}
		ready(function(){
			var heading = _createHeadingProgrammatically();
			var heading1 = registry.byId("hdg1");
			var heading2 = registry.byId("hdg2");
			var heading3 = registry.byId("hdg3");
			var btn;
			var lre = common.MARK.LRE;
			var rle = common.MARK.RLE;
			
			function getFirstChar(obj){
				var node = obj.labelDivNode || obj.labelNode;
				var text = node.innerHTML;
				return text ? text.charAt(0) : "";
			};			
		
			runner.register("dojox.mobile.test.bidi.doh.HeadingTests", [			
					
				function test_LTR_TextDir(){
					runner.assertEqual("ltr", heading1.get("textDir"));
					runner.assertEqual(lre, getFirstChar(heading1));
				},
				
				function test_RTL_TextDir(){
					runner.assertEqual("rtl", heading2.get("textDir"));
					runner.assertEqual(rle, getFirstChar(heading2));	
				},
				
				function test_auto_TextDir(){
					runner.assertEqual("auto", heading3.get("textDir"));
					runner.assertEqual(rle, getFirstChar(heading3));						
				},
				
				function test_ToolBarButton_TextDir(){
					btn = registry.byId("btn11");
					runner.assertNotEqual("rtl", btn.get("textDir"));
					runner.assertEqual(lre, getFirstChar(btn));
					btn = registry.byId("btn12");
					runner.assertEqual(getFirstChar(btn), lre);
					btn = registry.byId("btn21");
					runner.assertEqual(getFirstChar(btn), rle);
					btn = registry.byId("btn22");
					runner.assertEqual(getFirstChar(btn), rle);
					btn = registry.byId("btn24");
					runner.assertEqual(btn.get("textDir"), "ltr");
					runner.assertEqual(lre, getFirstChar(btn));
					btn = registry.byId("btn31");
					runner.assertEqual("auto", btn.get("textDir"));					
					runner.assertEqual(rle, getFirstChar(btn));
					btn = registry.byId("btn32");
					runner.assertEqual(lre, getFirstChar(btn));					
				},
						
				function test_change_textDir(){
					runner.assertEqual("auto", heading.get("textDir"));
					heading.set("textDir", "rtl");
					runner.assertNotEqual("ltr", heading.get("textDir"));
					runner.assertEqual(rle, getFirstChar(heading));
					runner.assertEqual(rle, getFirstChar(heading.backButton));
					btn = registry.byId("btn11");
					btn.set("textDir", "rtl");
					runner.assertEqual(rle, getFirstChar(btn));					
				},
				
				function test_change_Label(){
					heading3.set("label", "Text!");
					runner.assertEqual(lre, getFirstChar(heading3));
					heading3.set("label", "\u05e9\u05dc\u05d5\u05dd\u0021\u0021");
					runner.assertEqual(rle, getFirstChar(heading3));
					heading3.set("back", "\u05e9\u05dc\u05d5\u05dd\u0021\u0021 - back");
					runner.assertEqual(rle, getFirstChar(heading3.backButton));	
				},
				
				function test_change_Backlabel(){
					heading3.set("back", "\u05e9\u05dc\u05d5\u05dd\u0021\u0021 - back");
					runner.assertEqual(rle, getFirstChar(heading.backButton));	
				}
			]);
			runner.run();
		});
	})
</script>
</head>
<body>


	<div id="hdg1" data-dojo-type="dojox.mobile.Heading" data-dojo-props='label:"TextDir LTR...", textDir:"ltr"'>
		<span id="btn11" data-dojo-type="dojox.mobile.ToolBarButton" data-dojo-props='icon:"mblDomButtonWhitePlus",label:"DOM...  "' style="width:120px"></span>
		<span id="btn12" data-dojo-type="dojox.mobile.ToolBarButton" data-dojo-props='icon:"../../images/tab-icon-33w.png",label:"&#1495;&#1491;&#1513; image..."' style="width:120px"></span>
		<span data-dojo-type="dojox.mobile.ToolBarButton" data-dojo-props='icon:"../../images/tab-icons.png",iconPos:"29,116,29,29",label:"Sprite"' style="width:120px"></span>
		<span data-dojo-type="dojox.mobile.ToolBarButton" data-dojo-props='icon:"mblDomButtonWhitePlus"' style="float:right;"></span>

	</div><br>

	<div id="hdg2" data-dojo-type="dojox.mobile.Heading"  data-dojo-props='textDir:"rtl", label:"&#1495;&#1491;&#1513; arrow  RTL...", back:"textDir RTL..."'>
		<span id="btn21" data-dojo-type="dojox.mobile.ToolBarButton" data-dojo-props='icon:"mblDomButtonWhitePlus",label:"DOM...  "' style="width:120px"></span>
		<span id="btn22" data-dojo-type="dojox.mobile.ToolBarButton"  arrow="left" defaultColor="mblColorBlue" selColor="mblColorPink">&#1495;&#1491;&#1513; new...</span>
		<span id="btn23" data-dojo-type="dojox.mobile.ToolBarButton"  data-dojo-props=''>Test...</span>
		<span id="btn24" data-dojo-type="dojox.mobile.ToolBarButton"  data-dojo-props='arrow:"right", textDir:"ltr"'>Test ltr...</span>
		<span id="btn25" data-dojo-type="dojox.mobile.ToolBarButton"  data-dojo-props=''>Test...</span>
		<span data-dojo-type="dojox.mobile.ToolBarButton"  data-dojo-props='icon:"mblDomButtonWhitePlus"' style="float:right;"></span>

	</div><br>

	<div id="hdg3" data-dojo-type="dojox.mobile.Heading"  data-dojo-props=' back:"&#1495;&#1491;&#1513; BB...", textDir:"auto"'>&#1495;&#1491;&#1513; labeled Icon
		<span id="btn31" data-dojo-type="dojox.mobile.ToolBarButton" data-dojo-props='icon:"mblDomButtonWhitePlus",label:"&#1495;&#1491;&#1513; DOM"'></span>
		<span id="btn32" data-dojo-type="dojox.mobile.ToolBarButton" data-dojo-props='icon:"../../images/tab-icon-33w.png",label:"Image..."'></span>
		<span id="btn33" data-dojo-type="dojox.mobile.ToolBarButton" data-dojo-props='icon:"../../images/tab-icons.png",iconPos:"29,116,29,29",label:"&#1495;&#1491;&#1513; Sprite"'></span>
		<span id="btn34" data-dojo-type="dojox.mobile.ToolBarButton" data-dojo-props='icon:"mblDomButtonWhitePlus"' style="float:right;"></span>

	</div><br></body>
</html>
